

#include "sample_sys.h"


mpi_mem_map_table_s g_mem_map_table[] =
{
    /*************** fw base :0xCEC00000      ***************/
    {dsp_init_param,         0xC0001000,  0x1000},
    {dsp_log,                0xC0002000,  0x10000},
    {fw_orce,                0xC0020000,  0x200000},
    {fw_me,                  0XC0220000,  0x40000},
    {fw_binary,              0XC0260000,  0x40000},

    /*************** fw config base:0xCEC00000 **************/
    {dsp2_info,              0xCEC00000,  0x400},
    // {reserved_area, 			 0xCEC00400,  0xc00},
    {dsp_chip,               0xCEC01000,  0x400},
    //{reserved_area, 			 0xCEC01400,  0xc00},

    {dsp_default_cmd,        0xCEC02000,  0x1000},
    {dsp_normal_cmd,         0xCEC03000,  0x1000},
    {dsp_result_queue,       0xCEC04000,  0x100},
    //{reserved_area, 			 0xCEC01400,  0xf00},
    {display_vouta_addr,     0xCEC05000,  0x1000},
    {display_voutb_addr,     0xCEC06000,  0x1000},
    {bsb_desc_addr,          0xCEC07000,  0x4000},
    {osd_dram_addr,          0xCEC0B000,  0x400},
    //{reserved_area, 			 0xCEC0B400,  0xc00},
    {osd_clut_dram_addr,     0xCEC0C000,  0x400},
    //{reserved_area, 			 0xCEC0C400,  0xc00},
    {tv_dram_addr,           0xCEC0D000,  0x1000},
    {log_cb_addr,            0xCEC0E000,  0x1000},
    {disp_bank_addr,         0xCEC0F000,  0x2F1000},

	/*************** bsb base:0xC8200000 ***************/
    {bsb_buff,       		 0xC8200000,  0x400000},

    /*************** dsp base:0xC8600000 ***************/
	#ifndef MEM_FW_DEBUG
	{dsp_buff,       		 0xC8600000,  0x06600000},
	#else
    {dsp_buff,       		 0xC8600000,  0x500000},

	/***************dsp buff base:0xCF0EC000***************/
	{prevA,       	   0xC8B00000,  0x493E00}, 
	{prevB,       	   0xC8F93E00,  0x3EADDC}, 
	{prevC,    		   0x0,      		0x0}, 
	{cvbs_buff,        0xC937EBDC,  0x546000}, 
	{capture_buff,     0xC93D31DC,  0x1DC5E00}, 
	{me1_buff,         0xCB198FDC,  0x13C680}, 
	{recon_buff,       0xCB2D565C,  0x8E6200}, 
	{col_buff,         0xCBBBB85C,  0x47B80}, 
	{sec_capture_buff, 0xCBC033DC,  0xD2F000}, 
	{sec_me1_buff,     0xCC9323DC,  0x232800}, 
	{sec_recon_buff,   0xCCB64BDC,  0x3F4800}, 
	{sec_col_buff,     0xCCF593DC,  0xFD200}, 
	#endif

    /***************isp base:0xCF000000***************/
    {msg_addr_arm_osd,       				0xCF000000,  0x1000},
    {isp_aaa_fifo1_base,       				0xCF001000,  0x2000},/*2048*4*/
    {isp_aaa_fifo2_base,       				0xCF003000,  0xd000},/*12416*4*/
    {isp_input_lookup_table,       			0xCF010000,  0x1000},/*192*3*4*/
    {isp_matrix_dram_address,       		0xCF011000,  0x4000},/*16*16*16*4*/
    {isp_output_lookup_table,       		0xCF015000,  0x1000},/*256*4*/
    {isp_chroma_gain_curve,       			0xCF016000,  0x1000},/*128*2*/
    {isp_hot_pixel_thd_table,       		0xCF017000,  0x1000},/*3*128*2*/
    {isp_dark_pixel_thd_table,       		0xCF018000,  0x1000},/*3*128*2*/
    {isp_mctf_cfg_addr,       				0xCF019000,  0x1000},/*528*/
    {isp_k0123_table,       				0xCF01A000,  0x1000},/*24*2*/
    {isp_exposure_gain_curve,       		0xCF01B000,  0x1000},/*256*2*/
    {isp_luma_sharpening_alpha_table,       0xCF01C000,  0x1000},/*512*/
    {isp_coeff_fir1_addr,       			0xCF01D000,  0x1000},/*256*/
    {isp_coeff_fir2_addr,       			0xCF01E000,  0x1000},/*256*/
    {isp_coring_table,       				0xCF01F000,  0x1000},/*256*/
    {isp_vignette_r_gain,       			0xCF020000,  0x1000},/*33*33*2*/
    {isp_vignette_go_gain,       			0xCF021000,  0x1000},/*33*33*2*/
    {isp_vignette_ge_gain,       			0xCF022000,  0x1000},/*33*33*2*/
    {isp_vignette_b_gain,       			0xCF023000,  0x1000},/*33*33*2*/
    {isp_pixel_map_addr,       				0xCF024000,  0xC0000},/*384*1944*/
    {isp_fpn_reg_addr,       				0xCF0E4000,  0x1000},/*1024*/
    {isp_hor_still,       					0xCF0E5000,  0x3000},/*64*94*2*/
    {isp_ver_still,       					0xCF0E8000,  0x3000},/*64*94*2*/
    {isp_eis_enhance_turbo_buf,       		0xCF0EB000,  0x1000},/*192*/


};


int sgks_mpi_sample_SysInit(sgks_dsp_op_mode_e dsp_op_mode)
{
    int ret = 0;
    sgks_mpi_init_s mpi_init;

    //fw file
    #if 0
	mpi_init.fw_info.fw_type = SGKS_MPI_FW_UNENCRYPTION;
    mpi_init.fw_info.fw_file_num = 3;
    sprintf(mpi_init.fw_info.fw_path[0],"/home/lib/firmware/orccode.bin");
    sprintf(mpi_init.fw_info.fw_path[1],"/home/lib/firmware/orcme.bin");
    sprintf(mpi_init.fw_info.fw_path[2],"/home/lib/firmware/default_binary.bin");
	#else
	mpi_init.fw_info.fw_type = SGKS_MPI_FW_ENCRYPTION;
	mpi_init.fw_info.fw_file_num = 1;
    sprintf(mpi_init.fw_info.fw_path[0], "/home/lib/firmware/sgks_fw.bin");
	#endif

    // fw file load mem addr
    mpi_init.fw_info.code_addr[0].dsp_code_start 						= (u32 *)g_mem_map_table[fw_orce].phy_addr;
    mpi_init.fw_info.code_addr[0].dsp_code_size  						= g_mem_map_table[fw_orce].size;

    mpi_init.fw_info.code_addr[1].dsp_code_start 						= (u32 *)g_mem_map_table[fw_me].phy_addr;
    mpi_init.fw_info.code_addr[1].dsp_code_size  						= g_mem_map_table[fw_me].size;

    mpi_init.fw_info.code_addr[2].dsp_code_start 						= (u32 *)g_mem_map_table[fw_binary].phy_addr;
    mpi_init.fw_info.code_addr[2].dsp_code_size  						= g_mem_map_table[fw_binary].size;


    //fw init param

    memset(&mpi_init.dsp_init_param, 0, sizeof(sgks_fw_init_param_s));

	mpi_init.dsp_init_param.operation_mode				  				= dsp_op_mode;

    mpi_init.dsp_init_param.dsp_init_data_phy             				= (u32 *)g_mem_map_table[dsp_init_param].phy_addr;
    mpi_init.dsp_init_param.dsp_init_data_size            				= g_mem_map_table[dsp_init_param].size;

    mpi_init.dsp_init_param.default_binary_data_ptr_phy   				= (u32 *)g_mem_map_table[fw_binary].phy_addr;

    mpi_init.dsp_init_param.default_config_ptr_phy        				= (u32 *)g_mem_map_table[dsp_default_cmd].phy_addr;
    mpi_init.dsp_init_param.default_config_size           				= g_mem_map_table[dsp_default_cmd].size;

    mpi_init.dsp_init_param.cmd_data_ptr_phy              				= (u32 *)g_mem_map_table[dsp_normal_cmd].phy_addr;
    mpi_init.dsp_init_param.cmd_data_size                				= g_mem_map_table[dsp_normal_cmd].size;

    mpi_init.dsp_init_param.result_queue_ptr_phy          				= (u32 *)g_mem_map_table[dsp_result_queue].phy_addr;
    mpi_init.dsp_init_param.result_queue_size             				= g_mem_map_table[dsp_result_queue].size;

    mpi_init.dsp_init_param.dram_print_buf_addr_phy       				= g_mem_map_table[dsp_log].phy_addr;
    mpi_init.dsp_init_param.dram_printf_buf_size          				= g_mem_map_table[dsp_log].size;

    mpi_init.dsp_init_param.dsp2_info_ptr_phy             = (u32 *)g_mem_map_table[dsp2_info].phy_addr;
    mpi_init.dsp_init_param.chip_id_ptr_phy               = (u32 *)g_mem_map_table[dsp_chip].phy_addr;
    mpi_init.dsp_init_param.DSP_buf_ptr_phy               = (u32 *)g_mem_map_table[dsp_buff].phy_addr;
    mpi_init.dsp_init_param.DSP_buf_size				  = g_mem_map_table[dsp_buff].size;
    mpi_init.dsp_init_param.msg_addr_arm_osd_phy          = g_mem_map_table[msg_addr_arm_osd].phy_addr;
    mpi_init.dsp_init_param.msg_addr_arm_osd_size         = g_mem_map_table[msg_addr_arm_osd].size;

    mpi_init.dsp_init_param.bsb_phy                       				= (u32 *)g_mem_map_table[bsb_buff].phy_addr;
    mpi_init.dsp_init_param.bsb_size                      				= g_mem_map_table[bsb_buff].size;
    mpi_init.dsp_init_param.bsb_desc_phy                  				= g_mem_map_table[bsb_desc_addr].phy_addr;
    mpi_init.dsp_init_param.bsb_desc_size                 				= g_mem_map_table[bsb_desc_addr].size;

	#ifdef MEM_FW_DEBUG
    //////////////////////////////////////////////////////////////////
	mpi_init.dsp_init_param.dsp_init2_data.prevA_daddr					= g_mem_map_table[prevA].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.prevA_size					= g_mem_map_table[prevA].size; 
	mpi_init.dsp_init_param.dsp_init2_data.prevB_daddr					= g_mem_map_table[prevB].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.prevB_size					= g_mem_map_table[prevB].size; 
	mpi_init.dsp_init_param.dsp_init2_data.prevC_daddr					= g_mem_map_table[prevC].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.prevC_size					= g_mem_map_table[prevC].size; 
	mpi_init.dsp_init_param.dsp_init2_data.cvbs_buff_daddr				= g_mem_map_table[cvbs_buff].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.cvbs_buff_size				= g_mem_map_table[cvbs_buff].size; 

	mpi_init.dsp_init_param.dsp_init2_data.capture_buff_daddr			= g_mem_map_table[capture_buff].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.capture_buff_size			= g_mem_map_table[capture_buff].size; 
	mpi_init.dsp_init_param.dsp_init2_data.me1_buff_daddr				= g_mem_map_table[me1_buff].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.me1_buff_size				= g_mem_map_table[me1_buff].size; 
	mpi_init.dsp_init_param.dsp_init2_data.recon_buff_daddr				= g_mem_map_table[recon_buff].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.recon_buff_size				= g_mem_map_table[recon_buff].size; 
	mpi_init.dsp_init_param.dsp_init2_data.col_buff_daddr				= g_mem_map_table[col_buff].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.col_buff_size				= g_mem_map_table[col_buff].size; 
	
	mpi_init.dsp_init_param.dsp_init2_data.sec_capture_buff_daddr		= g_mem_map_table[sec_capture_buff].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.sec_capture_buff_size		= g_mem_map_table[sec_capture_buff].size; 
	mpi_init.dsp_init_param.dsp_init2_data.sec_me1_buff_daddr			= g_mem_map_table[sec_me1_buff].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.sec_me1_buff_size			= g_mem_map_table[sec_me1_buff].size; 
	mpi_init.dsp_init_param.dsp_init2_data.sec_recon_buff_daddr			= g_mem_map_table[sec_recon_buff].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.sec_recon_buff_size			= g_mem_map_table[sec_recon_buff].size; 
	mpi_init.dsp_init_param.dsp_init2_data.sec_col_buff_daddr			= g_mem_map_table[sec_col_buff].phy_addr; 
	mpi_init.dsp_init_param.dsp_init2_data.sec_col_buff_size			= g_mem_map_table[sec_col_buff].size; 
    #endif
	
    ret = sgks_mpi_sys_Init(&mpi_init);
    if (ret < 0)
    {
        return -1;
    }

    return SGKS_SUCCESS;
	
}




